/*
 * @Author: your name
 * @Date: 2022-01-18 17:19:10
 * @LastEditTime: 2022-01-19 11:23:15
 * @LastEditors: Please set LastEditors
 * @Description: socket.io 配置
 * @FilePath: \blog-api\src\socketIo\socket.ts
 */
// import { Server } from "socket.io";
const io = require("socket.io")({ cors: true })
// const io = new Server({ /* options */ });
io.on("connection", (socket) => {
  console.error(socket.id)
  socket.join("room 237"); // 将用户分配房间
  console.log(socket.rooms); // Set { <socket.id>, "room 237" }
  socket.to("room 237").emit("private", socket.id, '我回归了'); // 将用户分配房间

  // ...
  socket.on("private message", (anotherSocketId, msg) => {
    console.log(msg, anotherSocketId)
    socket.to("room 237").emit("private", socket.id, msg);

    socket.emit("an event", { some: msg });
  });
});

io.listen(2000);